﻿using System;
using zyconfig;

namespace zymain
{
    public class ControlLog
    {
        public static bool AddCreateISOLog(string UserID, string FilePath, string MainKay)
        {
            bool flag;
            using (DbOperHandler _open = new Common().Doh())
            {
                string sql = string.Empty;
                if (_open.dbType.ToString().Equals("ORACLE") || _open.odbType.ToString().Equals("ORACLE"))
                    sql = "insert into Disk_制作信息 (制作人,文件名称,制作时间,主键码,编号) values(" + UserID + ",'" + FilePath + "','" + DateTime.Now.ToString() + "'," + MainKay + ",DISK_文件信息表_编号.NEXTVAL)";
                else
                    sql = "insert into Disk_制作信息 (制作人,文件名称,制作时间,主键码) values(" + UserID + ",'" + FilePath + "','" + DateTime.Now.ToString() + "'," + MainKay + ")";
                _open.SqlCmd = sql;
                try
                {
                    _open.ExecuteSqlNonQuery();
                    flag = true;
                }
                catch { flag = false; }
            }
            return flag;
        }


        public static bool AddUpLoadLog(string tableName, string UserID, string FilePath, string MainKay)
        {
            bool flag;
            int num = FilePath.LastIndexOf(".");
            string str = string.Empty;
            if (num > 0)
            {
                str = FilePath.Substring(num + 1);
            }
            using (DbOperHandler _open = new Common().Doh())
            {
                string sql=string.Empty;
                switch (tableName)
                {
                    case "0":
                        sql = "Insert into Disk_上传日志 (上传人,上传时间,上传文件,主键码,文件类型) values(" + UserID + ",'" + DateTime.Now.ToString() + "','" + FilePath + "'," + MainKay + ",'" + str + "')";
                        break;
                    case "1":
                        sql = "Insert into Disk_单册上传日志 (上传人,上传时间,上传文件,登录号,文件类型) values(" + UserID + ",'" + DateTime.Now.ToString() + "','" + FilePath + "','" + MainKay + "','" + str + "')";
                        break;
                    case "2":
                        sql = "Insert into Disk_情报检索上传日志 (上传人,上传时间,上传文件,主键码,文件类型) values(" + UserID + ",'" + DateTime.Now.ToString() + "','" + FilePath + "'," + MainKay + ",'" + str + "')";
                        break;
                }
                _open.SqlCmd = sql;
                try
                {
                    _open.ExecuteSqlNonQuery();
                    flag = true;
                }
                catch (Exception ex){
                    Console.WriteLine(sql);
                    Console.WriteLine(ex.Message);
                    flag = false;
                }
            }
            return flag;
        }

        public static bool UpdateSqKt(string strMainKay)
        {
            bool flag;
            using (DbOperHandler _open = new Common().Doh())
            {
                string sql = "Update Disk_申请开通 set 是否开通=1 where 主键码=" + strMainKay;
                _open.SqlCmd = sql;
                try
                {
                    _open.ExecuteSqlNonQuery();
                    flag = true;
                }
                catch { flag = false; }
            }
            return flag;
        }
    }
}
